package interIterator;

import java.util.Scanner;

/**
 * Created by hps on 17-4-30.
 */
public class InterIterApp {
    public static void main(String[] args) {
        LinkList theList = new LinkList();
        ListIterator iter1 = theList.getIterator();
        long value;

        iter1.insertAfter(20);
        iter1.insertAfter(40);
        iter1.insertAfter(80);
        iter1.insertBefore(60);

        while (true) {
            System.out.print("Enter first letter 0f show, reset, ");
            System.out.print("next, get, before, after, delete: ");
            char choice = getChar();
            switch (choice) {
                case 's':
                    if(!theList.isEmpty())
                        theList.displayList();
                    else
                        System.out.println("List is empty");
                    break;
                case 'r':
                    iter1.reset();
                    break;
                case 'n':
                    if(!theList.isEmpty() && !iter1.atEnd())
                        iter1.nextLink();
                    else
                        System.out.println("Can't got to next link");
                    break;
                case 'g':
                    if(!theList.isEmpty()) {
                        value = iter1.getCurrent().dData;
                        System.out.println("Returned " + value);
                    } else
                        System.out.println("List is empty");
                    break;
                case 'b':
                    System.out.print("Enter value to insert: ");
                    value = getInt();
                    iter1.insertBefore(value);
                    break;
            }
        }
    }

    public static String getString() {
        Scanner scanner = new Scanner(System.in);
        return scanner.nextLine();
    }

    public static char getChar() {
        return getString().charAt(0);
    }

    public static  int getInt() {
        return Integer.parseInt(getString());
    }
}
